<template>
  <page :better-scroll="true">
    <template slot="extra-top">
      <!--      <account-warm></account-warm>-->
      <order-type
        :type="type"
        @current-type="currentType"></order-type>
    </template>
    <order-status-all v-if="type === 0" :orderList="orderList"></order-status-all>
    <order-status-uncleared v-if="type === 1" :orderList="orderList"></order-status-uncleared>
    <order-status-dispatched v-if="type === 2" :orderList="orderList"></order-status-dispatched>
    <order-status-received v-if="type === 3" :orderList="orderList"></order-status-received>
    <order-status-refund v-if="type === 4" :orderList="orderList"></order-status-refund>
  </page>
</template>

<script type="text/ecmascript-6">
  import accountWarm from '../common/account-warm'
  import orderType from './order-type'
  import orderStatusAll from './order-status-all'
  import orderStatusUncleared from './order-status-uncleared'
  import orderStatusDispatched from './order-status-dispatched'
  import orderStatusRefund from './order-status-refund'
  import orderStatusReceived from './order-status-received'

  export default {
    data() {
      return {
        type: parseInt(this.$route.query.from),
        orderList:[]
      }
    },
    components: {
      accountWarm,
      orderType,
      orderStatusAll,
      orderStatusUncleared,
      orderStatusDispatched,
      orderStatusRefund,
      orderStatusReceived
    },
    methods: {
      currentType(n) {
        this.type = n;
        this.getOrderList();
      },
      getOrderList(){
        let orderStatus = '';
        let type = this.type;
        switch (type) {
          case 0:
            orderStatus = ''; //全部订单
            break;
          case 1:
            orderStatus = '0'; //待付款
            break;

          case 2:
            orderStatus = '1,2'; //待收货
            break;
          case 3:
            orderStatus = '3'; //待收货
            break;
          case 4:
            orderStatus = '4'; //已收货
            break;
        }
        this.doRequest.get('/order_list?order_status='+orderStatus).then(ret=>{
          this.orderList = ret.data;
        })
      }
    },
    created() {
      let showType = this.$route.query.from;
      if (typeof showType === 'undefined') {
        this.type = 0;
      }
      this.getOrderList();
    }
  }
</script>
